//
//  KFLRequest.m
//  KWNLaywerClient
//
//  Created by 孔六五 on 14/12/12.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "KFLRequest.h"

@implementation KFLRequest
@synthesize kflEngine;
@synthesize kflRequestBlock;

- (id)initRequest
{
    self = [super init];
    if (self) {
        self.kflEngine  = [[MKNetworkEngine alloc] init];
    }
    return self;
}

- (void)startToRequestWithBlock:(requestResultBlock)resultBlock;
{
}
#pragma mark - 加密过程 -
/*
 加密过程
 */
- (NSString *)getSignWithArray:(NSMutableArray *)array_sort{
    [array_sort sortUsingSelector:@selector(compare:)];
    NSString *string_count = [NSString string];
    for (int i = 0; i < [array_sort count]; i++)
    {
        string_count = [string_count stringByAppendingString:[array_sort objectAtIndex:i]];
    }
    string_count = [string_count stringByAppendingString:YXSecret_key];
    NSString *string_result = [self md5HexDigest:string_count];
    return string_result;
}

#pragma mark - 32位md5加密 -
/*
 32位md5加密
 */
- (NSString *)md5HexDigest:(NSString*)input{
    if(input){
        const char* str = [input UTF8String];
        unsigned char result[CC_MD5_DIGEST_LENGTH];
        CC_MD5(str, (CC_LONG)strlen(str), result);
        NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
        for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++)
        {
            [ret appendFormat:@"%02x",result[i]];
        }
        return ret;
    }
    else
    {
        return nil;
    }
}

- (NSString *)urlStrUTF8:(NSString *)urlstr;
{
    NSString *utf8str = [urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    return utf8str;
}

- (void)dealloc
{
    if (self.kflRequestBlock) {
        self.kflRequestBlock = nil;
    }
    
    if (self.kflEngine) {
        [self.kflEngine cancelAllOperations];
    }
}

@end
